package org.rvk.vms.utils.search;

/**
 * Enumeration of various properties or fields on which the search can be made in VMS.
 *
 * @author Ashish Kumar Sinha <aksinha.mail@gmail.com>
 */
public enum VolunteersSearchFields {
    NAME("namesmartcard"),
    SMARTCARD("smartcard"),
    MOBILE("mobile"),
    STATE("state"),
    DEPARTMENT("deptcode"),
    ROLE("rolecode");

    private final String entityPropertyName;

    private VolunteersSearchFields(String entityPropertyName){
        this.entityPropertyName = entityPropertyName;
    }

    public String getEntityPropertyName(){
        return this.entityPropertyName;
    }

    public String whereClause(String value){
        if(value == null){
            return entityPropertyName + " IS NULL " ;
        }
        if(this == NAME){
            return entityPropertyName + " LIKE '%" + value.trim() + "% ";
        } else {
            return entityPropertyName + " = '" + value.trim() + "' ";
        }
    }
}
